# only add PUBLIC dependencies as well
#   https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-a-package-configuration-file
include(CMakeFindDependencyMacro)

# Search in <PackageName>_ROOT:
#   https://cmake.org/cmake/help/v3.12/policy/CMP0074.html
if(POLICY CMP0074)
    cmake_policy(SET CMP0074 NEW)
endif()

# locate the installed CMake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules")

# optional dependencies
set(openPMD_HAVE_MPI @openPMD_HAVE_MPI@)
if(openPMD_HAVE_MPI)
    find_dependency(MPI)
    # deselect parallel installs if explicitly a serial install is requested
    set(openPMD_NOMPI_FOUND FALSE)
else()
    set(openPMD_NOMPI_FOUND TRUE)
endif()
set(openPMD_MPI_FOUND ${openPMD_HAVE_MPI})

set(openPMD_HAVE_HDF5 @openPMD_HAVE_HDF5@)
if(openPMD_HAVE_HDF5)
    set(HDF5_PREFER_PARALLEL ${openPMD_HAVE_MPI})
    find_dependency(HDF5)
endif()
set(openPMD_HDF5_FOUND ${openPMD_HAVE_HDF5})

set(openPMD_HAVE_ADIOS2 @openPMD_HAVE_ADIOS2@)
if(openPMD_HAVE_ADIOS2)
    set(openPMD_REQUIRED_ADIOS2_COMPONENTS CXX)
    if(openPMD_HAVE_MPI)
        LIST(APPEND openPMD_REQUIRED_ADIOS2_COMPONENTS MPI)
    endif()
    find_dependency(ADIOS2 COMPONENTS ${openPMD_REQUIRED_ADIOS2_COMPONENTS})
    unset(openPMD_REQUIRED_ADIOS2_COMPONENTS)
endif()
set(openPMD_ADIOS2_FOUND ${openPMD_HAVE_ADIOS2})

# define central openPMD::openPMD target
include("${CMAKE_CURRENT_LIST_DIR}/openPMDTargets.cmake")

# check if components are fulfilled and set openPMD_<COMPONENT>_FOUND vars
foreach(comp ${openPMD_FIND_COMPONENTS})
    if(NOT openPMD_${comp}_FOUND)
        if(openPMD_FIND_REQUIRED_${comp})
            set(openPMD_FOUND FALSE)
        endif()
    endif()
endforeach()
